/* eslint-disable */
import Vue from 'vue'
import  VueTouch from 'vue-touch'
Vue.use(VueTouch,{name:'v-touch'})

// 默认抛出错误
Vue.config.errorHandler = function(err, vm) {
  console.error(`Error: ${err.toString()}\n`);
}

Vue.config.warnHandler = function(msg, vm, trace) {
  console.warn(`Warn: ${msg}\nTrace: ${trace}`);
}
// 导入elementUI组件
import 'default-passive-events' // 解决浏览器passive警告
// import 'element-ui/lib/theme-chalk/index.css'
// Vue.use(ElementUI, {size: 'small', zIndex: 3000})

// 导入VantUI组件
import Vant from 'vant';
import 'vant/lib/index.css'
Vue.use(Vant)

import VantExt from '@/util/vant-ext.js'
VantExt.extends(Vue)

import { Toast, Dialog, Notify  } from 'vant'
// 重置所有 Toast 的默认配置
Toast.setDefaultOptions('loading', {
  message: '加载中...',
  forbidClick: true,
  duration: 0,
  className: 'load-user',
  icon: require('@/assets/img/home/logo_square.jpg'),
})

Vue.prototype.$toast = Toast
Vue.prototype.$dialog = Dialog
Vue.prototype.$notify = Notify
Vue.use(Toast)
Vue.use(Dialog)
Vue.use(Notify)

// 导入svg-icon
import '@/util/svg-icon.js'

// 导入全局样式
import '@/styles/index.scss'

// 导入路由
import router from '@/router/index'
// 导入vuex
import store from '@/vuex/index'

// 导入ajax工具,并挂载到全局VUE上
import Ajax from '@/util/ajax'
Vue.prototype.$ajax = Ajax
// 导入配置
import {moduleMap} from './settings.js'

import FortenList from '@/components/FortenList.vue'
Vue.component('FortenList', FortenList)


import FortenCollapse from '@/components/FortenCollapse.vue'
Vue.component('FortenCollapse', FortenCollapse)

import FortenScan from '@/components/FortenScan.vue'
Vue.component('FortenScan', FortenScan)

import StockItem from '@/components/StockItem.vue'
Vue.component('StockItem', StockItem)

import utils from '@/util/index.js'
import '@/filters/index.js'

import validator from '@/util/validator.js'
import dates from '@/util/dates.js'
import strings from '@/util/strings.js'
import pyutils from '@/util/pyutils.js'
import queryWrappers from '@/util/queryWrappers.js'
import parameters from '@/util/parameters.js'
import utilPrint from './util/utilPrint.js'

global.moduleMap = moduleMap
global.$ajax = Ajax
global.utils = Vue.prototype.utils = utils
global.validator = Vue.prototype.validator = validator
global.dates = Vue.prototype.dates = dates
global.strings = Vue.prototype.strings = strings
global.pyutils = Vue.prototype.pyutils = pyutils
global.queryWrappers = Vue.prototype.queryWrappers = queryWrappers
global.$newWrapper = Vue.prototype.$newWrapper = queryWrappers.newWrapper
global.parameters = Vue.prototype.parameters = parameters
global.utilPrint = Vue.prototype.utilPrint = utilPrint

//PDA最近一次扫描结果
window.PDAScan = null
//判断是否是pda扫描
window.isPDAScan = function() {
  return window.PDAScan != null ? true : false
}

//获取PDA扫描结果，操作完将清除上一次数据
window.getPDAScan =function() {
  let PDAScan = window.PDAScan
  window.PDAScan = null
  return PDAScan
}

/**扫描头扫描后通知方法
 * 此方法外部不可调用
 */
window.androidCallJS = function (para){
  window.PDAScan = null
  try {
    if ( para instanceof String ) para = JSON.parse(para)
    if (para && para.code) window.PDAScan = para.code
    window.fortenScan(window.PDAScan)
  } catch (e) {
    alert(e.toString());
  }
}

//盘点枪开始扫描
window.rfidList = []
window.scanBegin = function (para){
  if (window.callAndroid) {
    window.rfidList = []
    window.callAndroid.scanBegin()
    return true
  } else {
    alert("请使用RFID盘点枪进行操作");
    return false
  }
}

//盘点枪结束扫描
window.scanEnd = function (noCHeck){
  let rfidList = []
  if (window.callAndroid) {
    let scanRet = window.callAndroid.scanEnd()
    if (scanRet.length<1) {
      alert("使用RFID盘点枪未获取到数据");
      return false
    }
    rfidList = scanRet.split(',')

  } else {
    if (!noCHeck) alert("请使用RFID盘点枪进行操作");
  }
  return rfidList
}

//盘点枪单个扫描结果接收
window.rfidScanMsgGet = function (para){
  let home = global.vue.$children[0].$children[0]
  try {
    if ( para instanceof String ) para = JSON.parse(para)
    if (para && para.msg) home.rfidScanMsg  = para.msg
  } catch (e) {
    alert(e.toString());
  }
}

//盘点枪 结束盘点后执行，可被覆盖
/**
* @Description：${description}
 window.scanConfirm = (rfidList) => {
  //自己代码
  }
*/
window.scanConfirm = function (rfidList){
}

//通用消息、站内消息提示音 msg.mp3
window.playMsg = function (){
  if (window.callAndroid) {
    window.callAndroid.playMsg()
  } else {
    console.info('window.callAndroid不存在')
  }
}


//文本框扫描成功 scan_ok.wav
window.scanOk = function (){
  if (window.callAndroid) {
    window.callAndroid.scanOk()
  } else {
    console.info('window.callAndroid不存在')
  }
}

//文本框扫描失败 scan_ok.wav
window.scanError = function (){
  if (window.callAndroid) {
    window.callAndroid.scanError()
  } else {
    console.info('window.callAndroid不存在')
  }
}
//android 返回键 返回true：则执行物理按键返回功能
window.androidBack = function (){
  let ret = true
  if (window.androidBackCall) {
    ret = window.androidBackCall()
  }
  console.info('androidBack-main')
  return ret
}

// 导入根组件
import App from '@/App.vue'
Vue.config.productionTip = false
const vue = new Vue({
  render: h => h(App),
  store,
  router,
  created() {
  }
}).$mount('#root')
global.vue = vue
